﻿<!--
> Muaz Khan     - https://github.com/muaz-khan 
> MIT License   - https://www.webrtc-experiment.com/licence/
> Experiments   - https://github.com/muaz-khan/WebRTC-Experiment
-->

<!DOCTYPE html>
<html id="home" lang="en">

    <head>
        <title>TURN server installation Guide ® Muaz Khan</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
        <link rel="author" type="text/html" href="https://plus.google.com/+MuazKhan">
        <meta name="author" content="Muaz Khan">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <link rel="stylesheet" href="https://www.webrtc-experiment.com/style.css">
	
        <style>
            p { padding: .8em; }

            li {
                border-bottom: 1px solid rgb(189, 189, 189);
                border-left: 1px solid rgb(189, 189, 189);
                padding: .5em;
            }

            .image-container {
                margin: 2em 0;
                text-align: center;
            }

            .image-parent {
                border: 2px solid black;
                border-radius: 5px;
                margin: 0 2em;
            }

            .image-parent img { width: 100%; }
            
            .experiment h2 {
                color: rgb(26, 86, 214);
            }
            
            li h2 {
                color: rgb(223, 32, 101)!important;
            }
        </style>
        <!-- for HTML5 el styling -->
        <script>
            document.createElement('article');
            document.createElement('footer');
        </script>
	
        <script type="text/javascript" src="https://www.webrtc-experiment.com/syntax/sh_main.min.js"> </script>
        <script type="text/javascript" src="https://www.webrtc-experiment.com/syntax/sh_javascript.min.js"> </script>
        <script type="text/javascript" src="https://www.webrtc-experiment.com/syntax/sh_html.min.js"> </script>
        <link type="text/css" rel="stylesheet" href="https://www.webrtc-experiment.com/syntax/sh_style.css">
    </head>

    <body onload="sh_highlightDocument();">
        <article>
            <header style="text-align: center;">
                <h1>TURN server installation Guide ® <a href="http://www.MuazKhan.com/">Muaz Khan</a></h1>
            
                <p>
                    <a href="https://www.webrtc-experiment.com/">HOME</a>
                    <span> &copy; </span>
                    <a href="http://www.MuazKhan.com/" target="_blank">Muaz Khan</a>
                        
                    .
                    <a href="http://twitter.com/WebRTCWeb" target="_blank" title="Twitter profile for WebRTC Experiments">@WebRTCWeb</a>
                        
                    .
                    <a href="https://github.com/muaz-khan?tab=repositories" target="_blank" title="Github Profile">Github</a>
                        
                    .
                    <a href="https://github.com/muaz-khan/WebRTC-Experiment/issues?state=open" target="_blank">Latest issues</a>
                        
                    .
                    <a href="https://github.com/muaz-khan/WebRTC-Experiment/commits/master" target="_blank">What's New?</a>
                </p>
            </header>
            
            <div class="github-stargazers"></div>
            
            <blockquote class="inline">
                This document is aimed to explain TURN server installation steps for different operating systems.
            </blockquote>
            
            <section class="experiment">
                <h2>TURN installation on CentOS</h2>
                    <ol>
                        <li>
                            <h2>First Step: Download & Install Prerequisite for CentOS</h2>
                            <pre class="sh_javascript">
yum install -y make gcc cc gcc-c++ wget
yum install -y openssl-devel libevent libevent-devel mysql-devel mysql-server
</pre>
                        </li>
					
                        <li>
                            <h2>Second Step: Download & Install LibEvent modules</h2>
                            <pre class="sh_javascript">
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar xvfz libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable && ./configure
make && make install && cd ..

# you can use "sudo" if permission-denied kind of erros occurred.
# sudo make && sudo make install && cd ..
</pre>
                        </li>
					
                        <li>
                            <h2>Third Step: <a href="https://code.google.com/p/rfc5766-turn-server/wiki/newDownloadsSite" target="_blank">Download & Install</a> TURN modules</h2>
                            <pre class="sh_javascript">
wget http://turnserver.open-sys.org/downloads/v3.2.3.8/turnserver-3.2.3.8.tar.gz
tar -xvzf turnserver-3.2.3.8.tar.gz
cd turnserver-3.2.3.8
make && make install
</pre>
                        </li>
					
                        <li>
                            <h2>Fifth Step: Configure "turnserver.conf" file</h2>
                            <pre class="sh_javascript">
vi /etc/turnserver/turnserver.conf

# setting static accounts
# Remember, "static" accounts are not dynamically checked by the turnserver process.
user=username:password

# listen ports
listening-port=2222
listening-ip=127.1.1

# Now press "insert" key; then "Esc" key
# Then type:
:wq         #-- this command will save your settings and close turnserver.conf file

# if you don't want to save settings; and quite. Simply type:
:q
</pre>
                            You can:
                            <ol>
                                <li>
                                    Use Only STUN
                                </li>
                                <li>
                                    Use Only TURN
                                </li>
                                
                                <li>
                                    Use Both STUN and TURN
                                </li>
                                
                                <li>
                                    Discard requests from all SSL/TLS version of protocols
                                </li>
                                
                                <li>
                                    Use short-live credentials. Other authentication mechanisms coming soon in next few weeks.
                                </li>
                                
                                <li>
                                    You can disable DTLS and TLS.
                                </li>
                                
                                <li>
                                    You can set both static and dynamic accounts.
                                </li>
                                
                                <li>
                                    You can give anonymous access to TURN server as well.
                                </li>
                                
                                <li>
                                    You can set credentials for stun-only option as well; usually STUN-binding requests are anonymous.
                                </li>
                            </ol>
                        </li>
					
                        <li>
                            <h2>Sixth Step: Run TURN server instance</h2>
                            <pre class="sh_javascript">
cd /etc/turnserver/

turnserver -v -r  ip:port -a -b turnuserdb.conf -c turnserver.conf -u turn-username -r ip:port -p turn-password
</pre>
                            <ol>
                                <li>
                                    Replace "ip:port" with yours! E.g. 127.1.1:2222:
                                </li>
							
                                <li>
                                    <pre class="sh_javascript">
turnserver -v -r  127.1.1:2222 -a -b turnuserdb.conf -c turnserver.conf -u turn-username -r 127.1.1:2222 -p turn-password
</pre>
                                </li>
							
                                <li>
                                    Replace "turn-username" with custom-username; and "turn-password" with custom-password.
                                </li>
							
                                <li>
                                    <pre class="sh_javascript">
turnserver -v -r  127.1.1:2222 -a -b turnuserdb.conf -c turnserver.conf -u custom-username -r 127.1.1:2222 -p custom-password
</pre>
                                </li>
                            </ol>
                        </li>
					
                        <li>
                            <h2>Last Step: "Permanently" run TURN server instance</h2>
                            <pre class="sh_javascript">
nohup turnserver -v -r  ip:port -a -b turnuserdb.conf -c turnserver.conf -u turn-username -r ip:port -p turn-password &
</pre>

                            <ol>
                                <li>
                                    You can see that the entire TURN execution command is placed between "nohup" and "&".
                                </li>
							
                                <li>
                                    <pre class="sh_javascript">
<strong>nohup</strong> TURN-execution-command <strong>&</strong>
</pre>
                                </li>
                            </ol>
                        </li>
                    </ol>
            </section>
            
            <section class="experiment">
                <h2>TURN installation on Windows</h2><br />
                    <small>Note: Following section is taken from <a href="http://www.slideshare.net/amiteshawa/web-rtc-media-stra" target="_blank">slideshare</a>; and its credit goes to @amiteshawa!</small>
                    <ol>
                        <li>
                            Install "Cygwin" application
                        </li>
					
                        <li>
                            Follow all steps from above section. E.g. install all dependencies; LibEvent and TURN modules.
                        </li>
					
                        <li>
                            You'll face some issues when invoking "./configure" command for TURN configuration:
						
                            <ol>
                                <li><strong>Missing libpq.a, hiredis, postgreSql</strong></li>
                                <li>You can ignore them, because these modules are optional</li>
                            </ol>
                        </li>
					
                        <li>
                            During "make" command invocation; you'll face error like "<strong>error: 'struct sockaddr_in' has no member named 'sin_len'</strong>"
                        </li>
					
                        <li>
                            Edit "na_turn_ioaddr.c" and comment line number "169":
                            <pre class="sh_javascript">
vi /turnserver-1.8.4.0/src/client/na_turn_ioaddr.c

# commenting line number #169
# addr->s4.sin_len = sizeof(struct sockaddr_in);
</pre>
                        </li>
					
                        <li>
                            Now, "make" and "make install" commands for TURN modules installation will work.
                        </li>
					
                        <li>
                            Then copy "turnserver.conf" file from "../examples/etc/" directory to "/usr/local/etc/":
                        </li>
					
                        <li>
                            <pre class="sh_javascript">
cp /turnserver-1.8.4.0/examples/etc/turnserver.conf /usr/local/etc/
</pre>
                        </li>
					
                        <li>
                            Now, you can follow "fifth" step from previous section to edit "turnserver.conf" for setting "username", "password", "listening-port" and "listening-ip".
                        </li>
					
                    </ol>
            </section>
            
            <section class="experiment">
                <h2>TURN installation on Ubuntu</h2>
                    <pre class="sh_javascript">
// Please follow this link:
https://groups.google.com/d/msg/easyrtc/ypjJ5Yu3wZM/u5Lq6VNfabcJ
</pre>
            </section>
            
            <section class="experiment">
                <h2>reTurnServer installation on Ubuntu</h2><br />
                <small>Below words are taken from <a href="http://www.rtcquickstart.org/ICE-STUN-TURN-server-installation" target="_blank">this link</a>.</small>
                <blockquote class="inline">
                    "<a href="http://www.resiprocate.org/ReTurn_Overview" target="_blank">reTurn</a> is a highly efficient C++ open-source STUN/TURN server and client library.  It is an implementation of the latest STUN/TURN RFCs:  <a rel="nofollow" class="external text" href="http://tools.ietf.org/html/rfc5389">RFC5389</a> (STUN), and <a rel="nofollow" class="external text" href="http://tools.ietf.org/html/rfc5766">RFC5766</a> (TURN)."
                </blockquote>
                <ol>
                    <li>
                        <h2>First Step: Install reTurnServer:</h2>
                        <pre class="sh_javascript">
# Install the package using the apt-get utility on Debian/Ubuntu:
apt-get install resiprocate-turn-server

# or using yum on Fedora:
yum install resiprocate-turn-server
</pre>
                    </li>
                    
                    <li>
                        <h2>Second Step: Edit <code>reTurnServer.config</code> file:</h2>
                        <pre class="sh_javascript">
# you can use "vi" or "vim"
vim /etc/reTurnServer.config

# your IP addresses go here:
TurnAddress = your-first-ip
AltStunAddress = your-second-ip

# your domain goes here:
AuthenticationRealm = your-domain

# your desired password goes here:
LongTermAuthPassword = your-password
</pre>
                    </li>
                    
                    <li>
                        <h2>Last Step: ReStart reTurnServer:</h2>
                        <pre class="sh_javascript">
service resiprocate-turn-server restart
</pre>
                    </li>
                    
                    <li>
                        You can check ports and addresses reTurnServer is listenning on:
                        <pre class="sh_javascript">
netstat -nlp | grep reTurnServer
</pre>
                    </li>
                </ol>
            </section>

            <br />
            <section style="border: 1px solid rgb(189, 189, 189); border-radius: .2em; margin: 1em 3em;">
                <h2 id="feedback" style="border-bottom: 1px solid rgb(189, 189, 189); padding: .2em .4em;">Want to ask a Question?</h2>
                <div>
                    <textarea id="message" style="border: 1px solid rgb(189, 189, 189); height: 8em; margin: .2em; outline: none; resize: vertical; width: 98%;" placeholder="Feel free to ask any question regarding WebRTC!"></textarea>
                </div>
                <button id="send-message" style="font-size: 1em;">Ask a Question</button><small style="margin-left: 1em;">You can include your email for private conversation!</small>
            </section>
            
            <section class="experiment own-widgets latest-commits">
                <h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a href="https://github.com/muaz-khan/WebRTC-Experiment/commits/master" target="_blank">Latest Updates</a></h2>
                <div id="github-commits"></div>
            </section>
        </article>
    
        <a href="https://github.com/muaz-khan/WebRTC-Experiment" class="fork-left"></a>
        
        <footer>
            <p>
                <a href="https://www.webrtc-experiment.com/">WebRTC Experiments</a>
                © <a href="https://plus.google.com/+MuazKhan" rel="author" target="_blank">Muaz Khan</a>
                <a href="mailto:muazkh@gmail.com" target="_blank">muazkh@gmail.com</a>
            </p>
        </footer>
    
        <!-- commits.js is useless for you! -->
        <script src="https://www.webrtc-experiment.com/commits.js" async> </script>
    </body>
</html>
